package com.huangpuweb.task.controller;

import com.huangpuweb.task.model.HpPersonHouseStatistics;
import com.huangpuweb.task.model.HpSyrkAgeDistribute;
import com.huangpuweb.task.model.HpSyrkGender;
import com.huangpuweb.task.service.PersonDataService;
import com.huangpuweb.task.service.SyncSysDataService;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller
public class HpSocialZongZhiJob {
    @Resource
    private PersonDataService personDataService;
    @Resource
    private SyncSysDataService syncSysDataService;

    public void HpPersonData57From80Task() {
        LogFactory.getLog(this.getClass()).info("--------start-------HpPersonData57From80Task----------" + new Date());

        //年龄分段表
        List<HpSyrkAgeDistribute> ageList = personDataService.getHpSyrkAgeDistribute();
        syncSysDataService.truncate("age");
        LogFactory.getLog(this.getClass()).info("--------start-------年龄分段表插入成功----------" + new Date());

        for (HpSyrkAgeDistribute e : ageList) {

            syncSysDataService.insertPeopleAgeById(e);
//            String cjrq = e.getCjrq();
//            String age = syncSysDataService.getId(cjrq,"age");
//            if (age == null) {
//                for (HpSyrkAgeDistribute e1 : ageList){
//                    if (e1.getCjrq()==cjrq) {
//
//
//                    }
//                    }
//                }
            }


        //男女年龄分段
        List<HpSyrkGender> genderList = personDataService.getHpSyrkGender();
        syncSysDataService.truncate("gender");
        LogFactory.getLog(this.getClass()).info("--------start-------男女年龄分段表插入成功----------" + new Date());

        for (HpSyrkGender e : genderList) {


            syncSysDataService.insertPeopleGenderById(e);

//            String gender = syncSysDataService.getId( e.getTimes(),"gender");
//            if (gender == null) {
//                for (HpSyrkGender hpSyrkGender : genderList) {
//                    if (e.getTimes()==hpSyrkGender.getTimes()) {
//                syncSysDataService.insertPeopleGenderById(e);
//                LogFactory.getLog(this.getClass()).info("--------start-------男女年龄分段表插入成功----------" + new Date());
//                }
//                }
//            }
        }

        //实有人口房屋统计情况
        List<HpPersonHouseStatistics> houseList = personDataService.getHpPersonHouseStatistics();
        syncSysDataService.truncate("house");
        LogFactory.getLog(this.getClass()).info("--------start-------实有人口房屋统计情况表插入成功----------" + new Date());

        for (HpPersonHouseStatistics e : houseList) {


            syncSysDataService.insertPeopleById(e,"house");

//            String house = syncSysDataService.getId(e.getCjrq(),"house");
//            if (house == null) {
//                for (HpPersonHouseStatistics hp : houseList) {
//                    if (e.getCjrq()==hp.getCjrq()) {
//                        syncSysDataService.insertPeopleById(e,"house");
//                        LogFactory.getLog(this.getClass()).info("--------start-------实有人口房屋统计情况表插入成功----------" + new Date());
//                    }
//                }
//
//            }
        }

        //黄浦区实有人口概况
        List<HpPersonHouseStatistics> SyList = personDataService.getHpSyrkHpPopu();
        syncSysDataService.truncate("popu");
        LogFactory.getLog(this.getClass()).info("--------start-------黄浦区实有人口概况插入成功----------" + new Date());

        for (HpPersonHouseStatistics e : SyList) {


            syncSysDataService.insertPeopleById(e,"popu");
//            String popu = syncSysDataService.getId(e.getCjrq(),"popu");
//
//            if (popu == null) {
//                for (HpPersonHouseStatistics hp : SyList) {
//                    if (e.getCjrq()==hp.getCjrq()) {
//                        }
//                }
//
//            }
        }

        //实有人口区域分布
        List<HpPersonHouseStatistics> SyQuList = personDataService.getHpSyrkPopuDistribution();
        syncSysDataService.truncate("distribution");
        LogFactory.getLog(this.getClass()).info("--------start-------实有人口区域分布插入成功----------" + new Date());
        for (HpPersonHouseStatistics e : SyQuList) {


            syncSysDataService.insertPeopleById(e, "distribution");
//
//            String distribution = syncSysDataService.getId(e.getCjrq(),"distribution");
//            if (distribution == null) {
//                for (HpPersonHouseStatistics hp : SyQuList) {
//                    if (e.getCjrq()==hp.getCjrq()) {
//                        syncSysDataService.insertPeopleById(e, "distribution");
//
//                    }
//                }
//
//            }
        }

        //街道人口概况
        List<HpPersonHouseStatistics> streetList = personDataService.getHpSyrkStreet();
        syncSysDataService.truncate("street");
        LogFactory.getLog(this.getClass()).info("--------start-------街道人口概况表插入成功----------" + new Date());

        for (HpPersonHouseStatistics e : streetList) {

            syncSysDataService.insertPeopleById(e, "street");

//            String street = syncSysDataService.getId(e.getCjrq(),"street");
//            if (street == null) {
//                for (HpPersonHouseStatistics hp : streetList) {
//                    if (e.getCjrq()==hp.getCjrq()) {
//                        syncSysDataService.insertPeopleById(e, "street");
//                        LogFactory.getLog(this.getClass()).info("--------start-------街道人口概况表插入成功----------" + new Date());
//                    }
//                }
//
//            }
        }
    }
}
